<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/plat-style.css" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <span class="layui-breadcrumb" lay-filter="breadcrumb">
                      <a href="javascript:;">资讯</a>
                      <a ><cite>编辑</cite></a>
                    </span>
                    <div class="layui-inline" style="float:right;">
                        <button type="button" class="layui-btn layui-btn-sm"  onclick="history.go(-1);">返回列表</button>
                    </div>
                </div>
                <div class="layui-card-body" style="padding: 15px;">
                    <form class="layui-form" id="essayAddForm" enctype="multipart/form-data">
                        <input type="hidden" name="id" value="${essay.id}">
                        <div class="layui-form-item">
                            <label class="layui-col-sm1 layui-col-sm-offset1"><span class="red">*&nbsp;</span>封面图</label>
                            <div class="layui-input-block">
                                <label for="coverUrl" class="layui-btn layui-btn-sm layui-btn-primary">上传图片</label>
                                <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;" name="coverUrlFile" id="coverUrl"
                                       onchange="showImg(this)"/>
                                <img id="" src="${!empty essay.coverUrl ?essay.coverUrl:'' }" style="${empty essay.hasVideo ? 'display:none;':''}" width="180px" height="180px"/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-col-sm1 layui-col-sm-offset1">是否需要视频</label>
                            <div class="layui-col-sm4">
                                <div class="layui-col-sm5 layui-col-sm-offset1">
                                    <input type="radio" name="hasVideo" value="1" title="是" ${essay.hasVideo == 1 ?"checked='checked'":"" }>
                                    <input type="radio" name="hasVideo" value="0" title="否" ${essay.hasVideo == 0 ?"checked='checked'":"" }>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item showVideo" style="${essay.hasVideo != 1 ? 'display:none;':''}">
                            <label class="layui-col-sm1 layui-col-sm-offset1">视频</label>
                            <div class="layui-input-block">
                                <label for="videoUrl" class="layui-btn layui-btn-sm layui-btn-primary">上传视频</label>
                                <input accept="video/*" type="file" style="display:none;" name="videoUrlFile" id="videoUrl"
                                       onchange="showVideo(this)"/>
                                <video class="edui-upload-video  vjs-default-skin video-js" style="${essay.hasVideo != 1 ? 'display:none;':''}" src="${essay.hasVideo == 1 ? essay.videoUrl:''}" controls="" width="375px" height="200px" preload="meta" data-setup="{}">
                                    <source src="${essay.hasVideo == 1 ? essay.videoUrl:''}" type="video/com/156023497591881333"/>
                                </video>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-col-sm1 layui-col-sm-offset1"><span class="red">*&nbsp;</span>资讯标题</label>
                            <div class="layui-col-sm4">
                                <input type="text" name="title" autocomplete="off" class="layui-input" value="${essay.title}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-col-sm1 layui-col-sm-offset1"><span class="red">*&nbsp;</span>内容</label>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <textarea id="content" name="content" style="display: none">${essay.content}</textarea>
                                <script id="articleEditor" type="text/plain" style="width:100%;height:400px;"></script>
                            </div>
                        </div>
                    </form>
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="text-align:center">
                            <div class="layui-footer" style="left: 0;">
                                <button class="layui-btn" onclick="saveEssay()">保存</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript" src="/js/plugins/image/previewImg.js?v=2.1"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.all.js"> </script>
<script type="text/javascript" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    layui.config({
        //静态资源所在路径
        base: '/layuiadmin/'
    }).extend({
        //主入口模块
        index: 'lib/index'
    }).use(['index', 'form','layedit'], function(){
        var $ = layui.$,layer = layui.layer, form = layui.form, element = layui.element;

        form.on("radio", function (data) {
            var msg = data.value;
            if (msg == '0') {
                $(".showVideo").attr("style", "display:none;");
            } else if (msg == '1') {
                $(".showVideo").attr("style", "");
            }
        });
    });


    $(function () {
        var ue = UE.getEditor('articleEditor');
        UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
        UE.Editor.prototype.getActionUrl = function(action) {
            if (action == '/uploadFile') {
                return '/base/uploadRichFile';
            } else {
                return this._bkGetActionUrl.call(this, action);
            }
        };
        UE.getEditor('articleEditor').ready(function() {
            UE.getEditor('articleEditor').setContent($("#content").text());
        })

    });

    function saveEssay(){
        $("#content").text(UE.getEditor('articleEditor').getContent());
        $("#essayAddForm").ajaxSubmit({
            type: 'post',
            url: "/news/doEditEssay",
            data: $("#essayAddForm").serialize(),
            dataType: 'json',
            success: function (data) {
                if (data.status) {
                    layer.msg(data.desc,{icon:1});
                    setTimeout(function () {
                        window.location.href = "/news/essay";
                    }, 1000)
                } else {
                    layer.msg(data.desc,{icon:2});
                }
            },
            error: function () {
                layer.msg("请检查页面信息是否正确",{icon:2});
            }
        });
    }

</script>
</body>
</html>